import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/module_permissions_util.dart';
import 'package:enterprise_v6_app/app/data/entities/application/securtity_base_drawer.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/accident_events/accident_events_view.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/equipment_facilities/equipment_facilities_view.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/file_management/file_management_view.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/personnel_management/personnel_management_view.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/productive_process/productive_process_view.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/third_party/third_party_view.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

class BasicInformationController extends GetxController {
  /// scaffoldKey
  final scaffoldKey = GlobalKey<ScaffoldState>();

  /// 选中的页面
  int selectIndex = 0;

  @override
  void onInit() {
    super.onInit();
    initModule();
  }

  /// 根据后台权限初始化菜单
  void initModule() {
    ModulePermissionsUtil.removeRoleMenu(titleList: titleList, routes: AppRoutes.basicInformation);
    update();
  }

  final titleList = [
    SecurityBaseEntity(
      title: '档案管理',
      icon: AppImages.icon_file_management,
      expandTitle: '档案管理',
      currentPageTitle: 0,
      pages: [FileManagementPage()],
      path: '/fileManagement',
    ),
    SecurityBaseEntity(
      title: '生产过程',
      icon: AppImages.icon_production_process,
      expandTitle: '生产过程',
      currentPageTitle: 0,
      pages: [ProductiveProcessPage()],
      path: '/productiveProcess',
    ),
    SecurityBaseEntity(
      title: '设备设施',
      icon: AppImages.icon_equipment_facilities,
      expandTitle: '设备设施',
      currentPageTitle: 0,
      pages: [EquipmentFacilitiesPage()],
      path: '/equipmentFacilities',
    ),
    SecurityBaseEntity(
      title: '人员管理',
      icon: AppImages.icon_personnel_management,
      expandTitle: '人员管理',
      currentPageTitle: 0,
      pages: [PersonnelManagementPage()],
      path: '/personnelManagement',
    ),
    SecurityBaseEntity(
      title: '事故事件',
      icon: AppImages.icon_accident_events,
      expandTitle: '事故事件',
      currentPageTitle: 0,
      pages: [AccidentEventsPage()],
      path: '/accidentEvents',
    ),
    SecurityBaseEntity(
      title: '第三方',
      icon: AppImages.icon_third_party,
      expandTitle: '第三方',
      currentPageTitle: 0,
      pages: [ThirdPartyPage()],
      path: '/thirdParty',
    ),
  ];

  /// title选择切换
  /// [titleIndex] 标题索引
  /// [index] 页面索引
  void selectTitle(int titleIndex, int index) {
    titleList[titleIndex].currentPageTitle = index;
    update();
  }

  /// 点击左侧菜单
  /// [index] 索引
  void selectLeftMenu(int index) {
    selectIndex = index;
    update();
  }

  /// 点击展开菜单
  /// [index] 索引
  void selectExpandMenu(int index) {
    selectIndex = index;
    Get.back();
    update();
  }
}
